// 函数定义
function hello(name: string): void {
  console.log('Hello', name);
}
// 函数表达式
const hello2 = function (name: string): void {
  console.log(name);
};
// 箭头函数
const hello3 = (name: string): void => {
  console.log(name);
};

// js 原生函数不指定返回值，默认返回 undefined.
// ts 函数没有返回值，默认推断为 void
function hello5(name: string) {
  console.log('Hello', name);
}

// 推到返回值类型为string
function hello6(name: string) {
  console.log('Hello', name);
  return 'xxx';
}

// 注意与原生js中函数的默认返回值区别
function hello7(name: string): undefined {
  console.log('Hello', name);
  return undefined;
}

// 函数可选参数约束方式
function mySlice(arr: number[], start?: number, end?: number): number[] {
  return arr.slice(start, end);
}

console.log('==>', mySlice([1, 2, 3]));

// function mySlice2(start?: number, end?: number, arr: number[]): number[] {
//   return arr.slice(start, end);
// }

function mySlice3(arr: number[], start: number = 0, end?: number): number[] {
  console.log('start', start);
  console.log('end', end);
  return arr.slice(start, end);
}

console.log('mySlice3==>', mySlice3([1, 2, 3], 1, 2));

export {};
